class SearchesController < ApplicationController
	before_filter :escape_query
    
  # GET /search
  def show
    unless @search_text.blank?
      #@entries = ThinkingSphinx.search @search_text, :per_page=>20, :page=>@page
      q = "%#{@search_text}%"
      @entries = []
      @entries += Page.find(:all, :conditions=>["title LIKE ? OR content LIKE ?", q, q], :order=>'created_at DESC')
      @entries += Post.find(:all, :conditions=>["title LIKE ? OR content LIKE ?", q, q], :order=>'created_at DESC')
    end
    
    @entries ||= []
		flash.now[:notice] = I18n.t('search.empty', :search_text=>@search_text) if @entries.empty?
  end
  
  private
  
    def escape_query
      @search_text = CGI.escapeHTML(params[:q]) unless params[:q].blank?
    end
end
